package com.mk.admin.service.impl;

import com.mk.admin.mapper.MenuAddressMapper;
import com.mk.admin.model.ResultDto;
import com.mk.admin.model.entity.MenuAddressEntity;
import com.mk.admin.model.vo.MenuAddressVo;
import com.mk.admin.service.MenuAddressService;
import com.mk.admin.util.JSONCopy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class MenuAddressServiceImpl implements MenuAddressService {
    @Autowired
    private MenuAddressMapper menuAddressMapper;

    @Override
    public ResultDto select(MenuAddressVo menuAddressVo) {
        MenuAddressEntity entity = JSONCopy.copy(menuAddressVo, MenuAddressEntity.class);
        return ResultDto.data(menuAddressMapper.count(entity), menuAddressMapper.select(entity));
    }

    @Override
    public ResultDto add(MenuAddressVo menuAddressVo) {
        return ResultDto.data(menuAddressMapper.insert(JSONCopy.copy(menuAddressVo, MenuAddressEntity.class)));
    }

    @Override
    public ResultDto update(MenuAddressVo menuAddressVo) {
        return ResultDto.data(menuAddressMapper.updateById(JSONCopy.copy(menuAddressVo, MenuAddressEntity.class)));
    }

    @Override
    public ResultDto delete(int id) {
        return ResultDto.data(menuAddressMapper.deleteById(id));
    }


    @Override
    public ResultDto status(int id) {
        return ResultDto.data(menuAddressMapper.status(id));
    }

    @Override
    public ResultDto deleteBatchIds(List<MenuAddressVo> list) {
        List<Integer> ids = list.stream().map(MenuAddressVo::getId).collect(Collectors.toList());
        return ResultDto.data(menuAddressMapper.deleteBatchIds(ids));
    }
}
